{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">新增员工</h3>
    <table class="layui-table layui-table-form">

        {if condition="$eid gt 0"}
        <input type="hidden" name="eid" value="{$eid}" lay-verify="required">
        {else/}
        <tr>
            <td class="layui-td-gray">所在企业<font>*</font></td>
            <td colspan="5">
                <select name="eid" lay-verify="required" lay-reqText="请选择所属企业" lay-filter="asyncEidSelect"
                        id="async-eid-select">
                    <option value="0">系统管理员</option>
                    {volist name="enterprise" id="v"}
                    <option value="{$v.id}" {notempty name="$detail.eid"} {eq name="$v.id" value="$detail.eid"} selected{/eq}{/notempty} >{$v.title}</option>
                    {/volist}
                </select>
            </td>
        </tr>

        {/if}
      <tr>
          <td class="layui-td-gray">员工名称<font>*</font></td>
          <td>
              <input type="text" name="name" lay-verify="required" {notempty name="$detail.name"}value="{$detail.name}"
                     {/notempty} lay-reqText="请输入员工名称" autocomplete="off" placeholder="请输入员工名称" class="layui-input">
          </td>

          <td class="layui-td-gray">所在部门<font>*</font>
          </td>
          <td>
              <select name="did" lay-verify="required" lay-reqText="请选择所属部门" lay-filter="asyncDidSelect"
                      id="async-did-select">
                  <option value="">请选择所属部门</option>
                  {volist name="department" id="v"}
                  <option value="{$v.id}" {notempty name="$detail.did" } {eq name="$v.id" value="$detail.did" }
                          selected{/eq}{/notempty}>{$v.title}</option>
                  {/volist}
              </select>
          </td>
      </tr>
        <tr>
            <td class="layui-td-gray">员工性别<font>*</font></td>
            <td>
                <select name="sex" lay-verify="required" lay-reqText="请选择所属企业">
                    <option value="0" {notempty name="$detail.sex"}selected {/notempty}>保密</option>
                    <option value="1" {notempty name="$detail.sex"}selected {/notempty}>女</option>
                    <option value="2" {notempty name="$detail.sex"}selected {/notempty}>男</option>
                </select>
            </td>
            <td class="layui-td-gray">学历<font>*</font></td>
            <td >
                <input type="text" name="educational" lay-verify="required" {notempty name="$detail.educational"}value="{$detail.educational}" {/notempty} lay-reqText="请输入员工类型" autocomplete="off" placeholder="请输入员工学历" class="layui-input"></td>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">专业<font>*</font></td>
            <td >
                <input type="text" name="major" lay-verify="required" {notempty name="$detail.major"}value="{$detail.major}" {/notempty} lay-reqText="请输入员工专业" autocomplete="off" placeholder="请输入员工专业" class="layui-input"></td>
            </td>
            <td class="layui-td-gray">岗位<font>*</font></td>
            <td >
                <input type="text" name="position" lay-verify="required" {notempty name="$detail.position"}value="{$detail.position}" {/notempty} lay-reqText="请输入员工岗位" autocomplete="off" placeholder="请输入员工岗位" class="layui-input"></td>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">职称<font>*</font></td>
            <td >
                <input type="text" name="professional" lay-verify="required" {notempty name="$detail.professional"}value="{$detail.professional}" {/notempty} lay-reqText="请输入员工职称" autocomplete="off" placeholder="请输入员工职称" class="layui-input"></td>
            </td>
            <td class="layui-td-gray">入职时间<font>*</font></td>
            <td>
                <input id="employment_time" name="employment_time" autocomplete="off" {notempty name="$detail.fmt_employment_time"}value="{$detail.fmt_employment_time}" {/notempty} class="layui-input" value="" readonly lay-verify="required" placeholder="请选择入职时间" lay-reqText="请选择入职时间">
            </td>
        </tr>
        <input type="hidden" name="id" ,  {notempty name="$detail.id"}value="{$detail.id}" {/notempty} >
    </table>
    <div class="py-3">
	   <input type="hidden" name="scene" value="add">
      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','employeepicker'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool,employeepicker = layui.employeepicker;

        // 监听选择框的选择变化（如果有需要）
        form.on('select(asyncEidSelect)', function (data) {
            $.getJSON('/home/equipment/getEnterpirseDepartment?eid=' + data.value, function (res) {

                var html = '';
                layui.each(res.data, function (index, item) {
                    html += '<option value="' + item.pid + '">' + item.title + '</option>';
                });
                document.getElementById('async-did-select').innerHTML = html;
                form.render($('#async-did-select')); // 重新渲染select
                // 模拟数据输出

                console.log(res); // 被选中的值
            });
        });

		//监听提交
		form.on('submit(webform)', function (data) {
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/home/user/add", data.field, callback);
			return false;
		});

        var form = layui.form,
            tool=layui.tool,
            oaTool=layui.oaTool,
            laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#employment_time',
            type: 'date',
            format: 'yyyy-MM-dd',
            showBottom: false
        });


    }
</script>
{/block}
<!-- /脚本 -->